package top.withwings.bonus.bonus.util;

import org.thymeleaf.util.DateUtils;
import top.withwings.bonus.common.pojo.Period;

import java.util.Calendar;
import java.util.Date;

public class BonusDateUtils {

    public static Period fromYearMonth(String yyyyMM) {
        String[] yyyyAndMM = yyyyMM.split("-");
        Calendar calendar = DateUtils.create(Integer.valueOf(yyyyAndMM[0]), Integer.valueOf(yyyyAndMM[1]), 1);
        Date start = calendar.getTime();
        //加一个月再减一秒 到本月的最后时刻
        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.SECOND, -1);
        Date end = calendar.getTime();
        return new Period(start, end);
    }
}
